import * as echarts from '../../ec-canvas/echarts';

const app = getApp();

function initChart(canvas, width, height, dpr) {
  const chart = echarts.init(canvas, null, {
    width: width,
    height: height,
    devicePixelRatio: dpr // new
  });
  canvas.setChart(chart);

  var gradeDistribution = app.globalData.gradeDistribution;

  var option = {
    backgroundColor: "#ffffff",
    color: ["#37A2DA", "#32C5E9", "#67E0E3", "#91F2DE", "#FFDB5C", "#FF9F7F"],
    series: [{
      label: {
        normal: {
          fontSize: 14
        }
      },
      type: 'pie',
      center: ['50%', '50%'],
      radius: ['40%', '60%'],
      data: [{
        value: gradeDistribution[0].gradeNumber,
        name:  gradeDistribution[0].gradeName+gradeDistribution[0].gradeNumber+"次"
      }, {
        value: gradeDistribution[1].gradeNumber,
        name: gradeDistribution[1].gradeName+gradeDistribution[1].gradeNumber+"次"
      }, {
        value: gradeDistribution[2].gradeNumber,
        name: gradeDistribution[2].gradeName+gradeDistribution[2].gradeNumber+"次"
      }, {
        value: gradeDistribution[4].gradeNumber,
        name: gradeDistribution[4].gradeName+gradeDistribution[4].gradeNumber+"次"
       
      }, {
        value: gradeDistribution[3].gradeNumber,
        name: gradeDistribution[3].gradeName+gradeDistribution[3].gradeNumber+"次"
      }]
    }]
  };

  chart.setOption(option);
  return chart;
}


Page({

  /**
   * 页面的初始数据
   */
  data: {
    ec: {
      onInit: initChart
    }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})